package org.example.JUC.Tools;

import java.util.concurrent.CountDownLatch;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-10 17:25
 **/
public class JoinCountDownLatch {
    private static volatile CountDownLatch countDownLatch=new CountDownLatch(2);

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne=new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                System.out.println("child threadOne over");
                countDownLatch.countDown();
            }

        });

        Thread threadTwo=new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                System.out.println("child threadTwo over");
                countDownLatch.countDown();
            }

        });

        threadOne.start();
        threadTwo.start();

        System.out.println("wait all child thread over");
        countDownLatch.await();

        System.out.println("all child thread over");


    }




}